﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using GWEB.WebBase.Entity;
using GWEB.WebBase.Utility;
using GWEB.WebFrame.Public;

namespace GWEB.WebFrame.Models
{
    public class MealCourse
    {
        public PageInfo Init()
        {
            HttpRequest request = System.Web.HttpContext.Current.Request;
            PageInfo pg = new PageInfo();

            pg.Type = "MealCourse";
            pg.Title = "";
            pg.AddText = "新增";
            pg.EditText = "";
            pg.LocateText = "查询";
            pg.SMenuId = "JX05";
            pg.FileUrl = "../MealCourses/MealCourse";
            pg.Condition = "";
            pg.TableName = "cu_Contract_Class";
            pg.KeyFieldName = "id";
            pg.PopEditHeight = 550;
            pg.PopEditWidth = 760;
            pg.ConditionColumn = 2;
            HttpSessionState session = System.Web.HttpContext.Current.Session;
            pg.dict = BasePage.getDict(session);
            pg.Sop = BasePage.Grant(session, pg.SMenuId);
            pg.Sop.DEL = false;
            pg.Sop.EDIT_htm = " ";
            pg.Sop.ADD = true;
            DataRow drUser = BasePage.GetUser(session);
            String leagueId = Fun.cString(drUser["LeagueId"].ToString());
            pg.Tab.Add("课程", "LocatePara='';TabIndex=1;DataPageUrl='../Main/DataPageLay?type=BaseCourse&state=1';GoPage(1);DoDisp(0);");
            pg.Tab.Add("套餐", "LocatePara='';TabIndex=2;DataPageUrl='../Main/DataPageLay?type=MealCourse&state=2';GoPage(1);DoDisp(1);");
            pg.Button.Add("<li id=\"s0\" onclick=\"ShowModalUrl('popEdit', '../Course/BaseCourse?id=-1', '创建课程系列', '', '700', '500')\" class='layui-btn layui-btn-normal'><i class='layui-icon layui-icon-add-1'></i>课程系列</li>");
            pg.Button.Add("<li id=\"s1\" onclick=\"ShowModalUrl('popEdit', '../MealCourses/MealCourse?id=-1', '创建套餐', '', '700', '500')\" class='layui-btn layui-btn-normal'><i class='layui-icon layui-icon-add-1'></i>新增套餐</li>");

            pg.Script = "function DoDisp(id){" +
    " var len=$(\"#TabPage li\").length;if(id==1) FileUrl ='../MealCourses/MealCourse';if(id==0) FileUrl ='../Course/BaseCourse';for( var i=0;i<len;i++){if(i==id)$(\"#s\"+i).css('display', ''); else $(\"#s\"+i).css('display', 'none');$(\"#btn_add\").css('display', 'none');$(\"#popEdit\").css('display', 'none');}}";

            string DelUrl = "../MealCourses/MealCourse/DelMealCourse";
            pg.Sql = @"select * from (select id,ContName as Names,Remark,MaxLeave,MaxMakeUP,Price,LeagueId,Courses,
case  when IsClassHour=0 then (case  when HourFrequency=0 then '时长:'+convert(varchar,HourNumber)+'个月-无限次数' when HourFrequency>0 then '时长:'+convert(varchar,HourNumber)+'个月-'+convert(varchar,HourFrequency)+'/月' END)when IsClassHour=1 then '课时:'+convert(varchar,ClassHourNumber)+'/次课'   END as  IsClassHourContent ,
'<a class=''layui-btn layui-bg-red layui-btn-xs'' href=""javascript: Do(''" + DelUrl + @"'',{ id: '+ltrim(id)+',keyCode: GetKeyCode('''+ltrim(id)+''')})"" >删除</a>'  as link 
from  cu_Contract_Class) a where LeagueId=" + leagueId;

            ColumnInfo cl;
            cl = new ColumnInfo(); cl.FieldName = "Names"; cl.HeadText = "名称"; cl.Visible = true; cl.IsCondition = true; cl.ConditionPosition = 1; cl.Width = 80; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.FieldName = "IsClassHourContent"; cl.HeadText = "套餐类型"; cl.Visible = true; cl.Width = 80; pg.AddColumn(cl);

            cl = new ColumnInfo(); cl.FieldName = "Price"; cl.HeadText = "合同价格"; cl.Visible = true; cl.Width = 80; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.FieldName = "MaxLeave"; cl.HeadText = "最大请假数"; cl.Visible = true; cl.Width = 80; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.FieldName = "MaxMakeUP"; cl.HeadText = "最大补课数"; cl.Visible = true; cl.Width = 80; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.FieldName = "Remark"; cl.HeadText = "摘要"; cl.Visible = true; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.FieldName = "Courses"; cl.HeadText = "部分课程"; cl.Visible = false; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.FieldName = "link"; cl.HeadText = "操作"; cl.IsSort = false; pg.AddColumn(cl);
            return pg;
        }

    }
}